package com.mwh.yuantu.dao;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mwh.yuantu.dao.mapper.CollectionInfoMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mwh.yuantu.entity.CollectionInfoEntity;

/**
 * (CollectionInfo)表数据库访问层
 *
 * @author maweihong
 * @since 2023-11-01 09:47:29
 */
@Service
public class CollectionInfoDao extends ServiceImpl<CollectionInfoMapper , CollectionInfoEntity> {

    @Autowired
	private CollectionInfoMapper collectionInfoMapper;

    /**
     * 判断该视频是否已被用户收藏过了
     * @param mediaId 媒体主键
     * @param userId 用户id
     * @return
     */
    public int countByMediaIdAndUserId(@Param("mediaId") String mediaId, @Param("userId") String userId){
        return collectionInfoMapper.countByMediaIdAndUserId(mediaId , userId);
    }

    /**
     * 添加视频收藏
     * @param collectionInfo
     * @return
     */
    public int insert(CollectionInfoEntity collectionInfo){
        return collectionInfoMapper.insert(collectionInfo);
    }

    /**
     * 删除收藏的视频
     * @param collectionInfo
     * @return
     */
    public int delete(CollectionInfoEntity collectionInfo){
        return collectionInfoMapper.delete(collectionInfo);
    }

    /**
     * 获取用户的视频收藏列表
     * @param map 用户id
     * @return
     */
    public List<Map<String, Object>> listCollection(Map<String , Object> map){
        return collectionInfoMapper.listCollection(map);
    }

    /**
     * 删除收藏表中的内容
     * @param userIdArr 用户id数组
     * @return
     */
    public int deleteByUserIdArr(@Param("userIdArr") String[] userIdArr){
        return collectionInfoMapper.deleteByUserIdArr(userIdArr);
    }
}

